package com.jt.controller;

import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.vo.EasyUITable;
import com.jt.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jt.service.ItemService;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.List;

@RestController
@RequestMapping("/item")
public class ItemController {
	
	@Autowired
	private ItemService itemService;
	
	@RequestMapping("/query")
	public EasyUITable findItemByPage(Integer page,Integer rows){
		return itemService.findItemByPage(page,rows);
	}

	@RequestMapping("/save")
	public SysResult saveItem(Item item,ItemDesc itemDesc){
		try {
			return itemService.saveItem(item,itemDesc);
		}catch (Exception e){
			e.printStackTrace();
			return null;
		}
	}

	@RequestMapping("/update")
	public SysResult updateItem(Item item,ItemDesc itemDesc){
		itemService.updateItem(item,itemDesc);
		return SysResult.success();
	}

	@RequestMapping("/delete")
	public SysResult deleteItem(String[] ids){
		itemService.deleteItem(ids);
		return SysResult.success(ids);
	}

	@RequestMapping("updateStatus/{status}")
	public SysResult updateStatus(@PathVariable Integer status,Long... ids){
		itemService.updateStatus(ids,status);
		return SysResult.success();
	}

	@RequestMapping("/query/item/desc/{itemId}")
	public SysResult findItemDescById(@PathVariable Long itemId){
		ItemDesc itemDesc=itemService.findItemDescById(itemId);
		return SysResult.success(itemDesc);
	}
}
